package com.xidian.zhiancloud.controller.riskcontrol.riskidenva;

import com.github.pagehelper.Page;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.enums.UserResponseEnums;
import com.xidian.zhiancloud.model.Information;
import com.xidian.zhiancloud.model.riskcontrol.*;
import com.xidian.zhiancloud.model.syset.Organization;
import com.xidian.zhiancloud.model.syset.SysUser;
import com.xidian.zhiancloud.qo.BaseReqQuery;
import com.xidian.zhiancloud.service.riskcontrol.TRiskLedgerStatusServicve;
import com.xidian.zhiancloud.service.riskcontrol.riskidenva.*;
import com.xidian.zhiancloud.service.riskcontrol.riskpointslist.TEquipFacStatusService;
import com.xidian.zhiancloud.service.user.UserService;
import com.xidian.zhiancloud.service.user.usermanage.OrganizationService;
import com.xidian.zhiancloud.service.ypp.messageCenter.information.InformationService;
import com.xidian.zhiancloud.util.api.ExcelUtil2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 风险管控-风险辨识评价-风险辨识评价计划
 */
@RestController
@RequestMapping("/triskidentevalsta")
public class TRiskIdentEvalStatusController extends BaseController {

    /**
     * 风险管控-风险辨识评价计划
     */
    @Autowired
    TRiskIdentEvalStatusService tRiskIdentEvalStatusService;

    /**
     * 风险管控-风险点清单
     */
    @Autowired
    TEquipFacStatusService tEquipFacStatusService;

    /**
     * 消息中心
     */
    @Autowired
    InformationService informationService;

    /**
     * 风险辨识评价计划-分析评价任务分配
     */
    @Autowired
    TRiskTaskAllocationService tRiskTaskAllocationService;

    /**
     * 风险管控-风险点清单-设备设施清单-检查项
     */
    @Autowired
    TRiskCheckItemsService tRiskCheckItemsService;

    /**
     * 风险评价措施表
     */
    @Autowired
    TRiskAssessmentMeasuresService tRiskAssessmentMeasuresService;

    /**
     * 风险评价审核-审核记录
     */
    @Autowired
    TRiskAuditRecordsService tRiskAuditRecordsService;

    /**
     *  风险评价审核-审核-对象评价审核
     */
    @Autowired
    TRiskObjectEvaluationAuditService tRiskObjectEvaluationAuditService;

    /**
     * 组织机构
     */
    @Autowired
    OrganizationService organizationService;

    @Autowired
    HttpServletRequest request;

    /**
     * 风险辨识评价计划-流程记录查看
     */
    @Autowired
    TRiskCheckProcessService tRiskCheckProcessService;

    /**
     * 风险管控-风险台账
     */
    @Autowired
    TRiskLedgerStatusServicve tRiskLedgerStatusServicve;

    /**
     * 作业活动清单-检查项
     */
    @Autowired
    TRiskJobCheckItemService tRiskJobCheckItemService;

    /**
     * 工艺节点-检查项
     */
    @Autowired
    TRiskProcessInspectionItemService tRiskProcessInspectionItemService;

    @Autowired
    TRiskValueLevelService tRiskValueLevelService;


    /**
     * 用户表
     */
    @Autowired
    UserService userService;

    /**
     * 流程操作记录
     */
    @Autowired
    TRiskProcessOperationRecordService tRiskProcessOperationRecordService;

    /**
     * 风险辨识计划列表
     * @param reqdata 多对象集合
     * @param discerner 辨识人
     * @param evaluator 评价人
     * @param auditor 审核人                  
     * @param state 风险辨识评价计划的状态
     *      1 : 待发布 ;
     *      2 : 分解中 ;
     *      3 : 辨识中 ; 7 : 被退回(辨识) ;
     *      4 : 评价中/(已辨识) ; 8 : 被退回(评价) ;
     *      5 : 审核中/(已评价) ; 9 : 被退回(审核)/审核未通过 ; 10 : 已审核 ;
     *      0 : 已完成 ;
     * @param riskpointType 风险点清单类型 ss00 : 设备设施 ;  zy00 : 作业活动 ; gy00 : 工艺节点 ;
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/getTRiskIdentEvalStatusList")
    public ResultDTO getTRiskIdentEvalStatusList(BaseReqQuery reqdata,
           @RequestParam(value="state",required=false,defaultValue = "99")
              String state,
           @RequestParam(value="riskpointType",required=false)
              String riskpointType,
           @RequestParam(value = "discerner",required = false,
              defaultValue = "0") String discerner,
            @RequestParam(value = "evaluator",required = false,
              defaultValue = "0") String evaluator,
             @RequestParam(value = "auditor",required = false,
                 defaultValue = "0") String auditor,
             @RequestParam(value = "type",required = false,
                 defaultValue = "0") String type) {
        Long companyId=this.getSessionUserCompanyId();
        String userId = String.valueOf(this.getSessionUserid());
        
        //查找超级管理员用户
        SysUser user = userService.getByUserAndSuperAdministrator(companyId);
        
        Page<TRiskIdentEvalStatusList> pagedata = new Page<>();

        if(userId.equals(String.valueOf(user.getId()))) {
           pagedata = tRiskIdentEvalStatusService.getTRiIdeEvalStaSuperAdmin
                  (reqdata,companyId,state,riskpointType,userId,discerner,evaluator,auditor,type);
        } else if(!auditor.equals("0") && type.equals("4")) {//风险评价审核里面的列表
            pagedata = tRiskIdentEvalStatusService.getTRiIdeEvalStaAudit
                (reqdata,companyId,state,riskpointType,auditor,type,userId);
        } else if(!userId.equals(String.valueOf(user.getId())) && auditor.equals("0")) {
            pagedata = tRiskIdentEvalStatusService.getTRiIdeEvalSta
                (reqdata,companyId,state,riskpointType,userId,discerner,evaluator,type);
        }

        Map<String, Object> data = new HashMap<String, Object>();
        data.put("datalist", pagedata);
        data.put("total", pagedata.getTotal());
        data.put("PageTotal", pagedata.getPages());
        data.put("PageNum", pagedata.getPageNum());
        data.put("PageSize", pagedata.getPageSize());
        return ResultDTO.successOf(data, GeneralResponseEnums.SUCCESS);
    }

    /**
     *  风险管控-风险辨识评价-风险辨识评价计划-添加风险辨识评价计划
     * @param tefsId 风险点清单ID
     * @param riskpointType 风险点清单类型
     *       ss00 : 设备设施 ;
     *       zy00 : 作业活动 ;
     *       gy00 : 工艺节点 ;
     * @return 返回 ResultDTO对象
     *
     */
    @RequestMapping("/addTRiskIdentEvalStatusList")
    public ResultDTO addTRiskIdentEvalStatusList
         (TRiskIdentEvalStatusList triesdata,
         @RequestParam(value = "tefsId",required = false,
             defaultValue = "0") String tefsId,
         @RequestParam(value="riskpointType",required=false)
             String riskpointType) {
        try{
            Long companyId=this.getSessionUserCompanyId();
            triesdata.setOrgId(request.getParameter("orgid"));
            triesdata.setHeadId(request.getParameter("personidenEva"));
            triesdata.setRecipientId(request.getParameter("personidenEva"));
            triesdata.setType(riskpointType);
            triesdata.setCreateId(String.valueOf(this.getSessionUserid()));
            tRiskIdentEvalStatusService.insertTRiskIdentEvalStatusList
                    (triesdata,companyId,tefsId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 修改查看
     * @param id 风险辨识计划ID
     * @return 返回ResultDTO对象
     */
    @RequestMapping("/getUpdateIdentEvalSta")
    public ResultDTO getUpdateIdentEvalSta ( @RequestParam("id") String id ) {
        Long companyId=this.getSessionUserCompanyId();
        List<TRiskIdentEvalStatusList> identEvalSta =
                tRiskIdentEvalStatusService.getById(companyId, id);
        List<TRiskTaskAllocationList> taskAllocat =
                tRiskTaskAllocationService.getById(companyId,id);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("identEvalSta", identEvalSta);//风险辨识计划
        data.put("taskAllocat", taskAllocat);//风险辨识清单
        return ResultDTO.successOf(data,GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险管控-风险辨识评价-风险辨识评价计划-风险辨识计划编辑
     * @param id 风险辨识计划ID
     * @param tefsId 风险点ID
     * @param taskAllocatId 分析评价任务分配ID
     * @param riskpointType 风险点清单类型 ss00 : 设备设施 ; zy00 : 作业活动 ; gy00 : 工艺节点 ;
     * @param evaluationMethodId 评价方法ID
     * @return 返回ResultDTO对象
     * todo 这块的方法要进行修改
     */
    @RequestMapping("/updateIdentEvalSta")
    public ResultDTO updateIdentEvalSta(
        @RequestParam("riskName") String riskName,
        @RequestParam(value ="remarks",required = false,
            defaultValue = "null") String remarks,
        @RequestParam(value = "id",required = false,
           defaultValue = "0") String id, 
        @RequestParam(value = "tefsId",required = false,
           defaultValue = "0") String tefsId,
        @RequestParam(value="riskpointType",required=false)
            String riskpointType,
         @RequestParam("evaluationMethodId") String evaluationMethodId,
         @RequestParam(value = "taskAllocatId",required = false,
                 defaultValue = "0") String taskAllocatId) {
        Long companyId=this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startTimes = new Date();
        Date deadlineIdens = new Date();
        Date deadlineEvals = new Date();
        try{
            startTimes = sdf.parse("startTime");
            deadlineIdens = sdf.parse("deadlineIden");
            deadlineEvals = sdf.parse("deadlineEval");
        }catch (Exception e){
            e.getMessage();
        }
        List<TRiskIdentEvalStatusList> identEvalList=
                tRiskIdentEvalStatusService.getById(companyId,id);
        for (TRiskIdentEvalStatusList ident: identEvalList) {
            //判断选择的辨识评价类型是不是一样的类型
            if (!riskpointType.equals(ident.getRiskpointType())) {
                //选择的类型和原来的类型不一致,将原来的类型删除 ,将评价任务分配ID传递过来进行删除
                tRiskTaskAllocationService.removeTaskAllocation(taskAllocatId);
                tRiskIdentEvalStatusService.updateIdentEvalSta(riskName,startTimes,deadlineIdens,
                    deadlineEvals,remarks, riskpointType,companyId, tefsId, id, 
                    evaluationMethodId);
            }
        }
        //选择的类型和原来的一致,那就是1 ,修改计划,
         tRiskIdentEvalStatusService.updateIdentEval(companyId,riskName,startTimes,deadlineIdens,deadlineEvals,
             remarks,riskpointType,id,taskAllocatId,tefsId,userId);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价-查看按钮
     * @param id 风险辨识评价计划ID
     * @param type 区分调用查看的页面  1 : 风险辨识评价计划 ; 2 : 辨识页面 ; 3 : 评价页面 ; 4 :评价审核             
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/getCheckTRiTaAllButton")
    public ResultDTO getCheckTRiTaAllButton(BaseReqQuery reqdata,
          @RequestParam("id") String id, @RequestParam("type") String type) {
        
        Long companyId=this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        
        Page<TRiskIdentEvalStatusList> evaPagedata =
                tRiskIdentEvalStatusService.getById(reqdata,companyId, id);
        
        Page<TRiskTaskAllocationList> pagedata = tRiskTaskAllocationService
                .getCompanyIdAndPageTaskAll(reqdata,companyId,id,userId,type);
        
        Map<String, Object> data = new HashMap<String, Object>();
        
        data.put("evaPagedata", evaPagedata);//风险辨识计划
        data.put("datalist", pagedata);//风险辨识评价计划-分析评价任务分配里的风险点
        data.put("total", pagedata.getTotal());
        data.put("PageTotal", pagedata.getPages());
        data.put("PageNum", pagedata.getPageNum());
        data.put("PageSize", pagedata.getPageSize());

        return ResultDTO.successOf(data,GeneralResponseEnums.SUCCESS);
        
    }

    /**
     * 二级风险点列表
     * @param triskidentevalsId 风险辨识计划ID
     * @param reqdata 参数集合
     * @param status 风险点的状态
     *   1 : 待发布 ;
     *   2 : 分解中 ; 3 : 已分解 ;
     *   4 : 辨识中 ; 5 : 已辨识 ; 6 : 被退回(辨识) ;
     *   7 : 评价中 ; 8 : 已评价 ; 9 : 被退回(评价) ;
     *   10 : 审核中 ; 11 : 已审核 ; 12 : 被退回(审核) ;
     *   0 : 完成 ;
     * @return 返回ResultDTO对象
     */
    @RequestMapping("/getTRiskTaskAllocation")
    public ResultDTO getTRiskTaskAllocation(BaseReqQuery reqdata,
          @RequestParam(value="status",required=false,
                  defaultValue = "99") String status,
          @RequestParam(value="triskidentevalsId",required=false,
              defaultValue = "0") String triskidentevalsId) {
        Long companyId=this.getSessionUserCompanyId();
        Page<TRiskTaskAllocationList> pagedata = tRiskTaskAllocationService
           .getTRiskTaskAllocation(reqdata,companyId,triskidentevalsId,status);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("datalist", pagedata);
        data.put("total", pagedata.getTotal());
        data.put("PageTotal", pagedata.getPages());
        data.put("PageNum", pagedata.getPageNum());
        data.put("PageSize", pagedata.getPageSize());
        return ResultDTO.successOf(data, GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价-查看-查看按钮
     * @param taskAllocatId 风险评价计划任务分配ID
     * @param riskpointsId 风险点ID
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/getLookOverTRiskIdentEvalStatus")
    public ResultDTO getLookOverTRiskIdentEvalStatus (
         @RequestParam("riskpointsId") String riskpointsId,
        @RequestParam(value="taskAllocatId",required = false,
           defaultValue = "0") String taskAllocatId,
         @RequestParam("type") String type ) {
        Long companyId=this.getSessionUserCompanyId();
        Map<String, Object> data = new HashMap<String, Object>();
        //风险辨识-通过 风险评价计划任务分配ID 进行查询
        List<TRiskTaskAllocationList> tRiskTaskAllocations =
                tRiskTaskAllocationService.getByIds(companyId,taskAllocatId,type);
        String riskpointType = "";
        for (TRiskTaskAllocationList tRall : tRiskTaskAllocations) {
          TRiskIdentEvalStatusList tRiskIdentEval=tRiskIdentEvalStatusService.
              getByIds(tRall.getCompanyId(),tRall.getTriskidentevalsId().toString());
            riskpointType=tRiskIdentEval.getRiskpointType();
        }
        //检查项 - 通过 风险评价计划任务分配ID 进行查询
        if(riskpointType.equals("ss00")){//设备设施
            List<TRiskCheckItemsList> tRiskCheckItems =
                tRiskCheckItemsService.getById(companyId,taskAllocatId);
            data.put("tRiskCheckItems", tRiskCheckItems);//设备设施检查项
        }else if(riskpointType.equals("zy00")){//作业活动
            List<TRiskJobCheckItemList> tRiskCheckItems = tRiskJobCheckItemService.
                getByIds(companyId, taskAllocatId);
            data.put("tRiskCheckItems", tRiskCheckItems);//作业活动检查项
        }else if(riskpointType.equals("gy00")){//工艺节点
            List<TRiskProcessInspectionItemList> tRiskCheckItems = 
                tRiskProcessInspectionItemService.getByIds(companyId, taskAllocatId);
            data.put("tRiskCheckItems", tRiskCheckItems);//工艺节点检查项
        }
        //风险点信息-使用风险点ID进行查询
        List<TEquipFacStatusList> tEquipFacStatus =
                tEquipFacStatusService.getById(companyId,riskpointsId);
        //审核记录-使用 风险评价计划任务分配ID  进行查询
        List<TRiskAuditRecordsList> tRiskAuditRecords= tRiskAuditRecordsService
                .getByRIESIdAndRPointId(companyId,taskAllocatId);
        
        data.put("tRiskTaskAllocations", tRiskTaskAllocations);//风险辨识
        data.put("tEquipFacStatus", tEquipFacStatus);//风险点信息
        data.put("tRiskAuditRecords", tRiskAuditRecords);//审核记录
        return ResultDTO.successOf(data,GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价-删除按钮
     * @param id 风险辨识评价计划ID
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/removeTRiskIdentEvalStatus")
    public ResultDTO removeTRiskIdentEvalStatus(@RequestParam("id") String id) {
        int result = tRiskIdentEvalStatusService.
                removeTRiskIdentEvalStatus(id);
        if(result != 0){
            tRiskTaskAllocationService.removeTRiskTaskAllocation(id);
            tRiskProcessOperationRecordService.deleteByProOperRecId(id);
        }else if(result == 0){
            return ResultDTO.errorOf(GeneralResponseEnums.DELETE_FAILED);
        }
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 分析评价任务分配-删除按钮
     * @param id 分析评价任务分配ID
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/removeTaskAllocation")
    public ResultDTO removeTaskAllocation(@RequestParam("id") String id) {
        tRiskTaskAllocationService.removeTaskAllocation(id);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价计划-发布
     * @param id 风险辨识评价计划ID
     * @param state 状态(待发布 1 ~ 分解中 2)
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/releaseRiskIdenEva")
    public ResultDTO releaseRiskIdenEva(@RequestParam("id") String id,
        @RequestParam("state") String state) {
        Long companyId=this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        tRiskIdentEvalStatusService.decomposeRiskIdenEva(companyId,id,state,userId);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 分解显示的页面
     * @param id 风险辨识评价计划ID
     * @return 返回ResultDTO对象
     */
    @RequestMapping("/shreddedDataPage")
    public ResultDTO shreddedDataPage(BaseReqQuery reqdata,@RequestParam("id") String id) {
        Long companyId=this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        Page<TRiskTaskAllocationList> pagedata =tRiskTaskAllocationService.
            shreddedDataPage(reqdata,companyId,id,userId);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("datalist", pagedata);
        data.put("total", pagedata.getTotal());
        data.put("PageTotal", pagedata.getPages());
        data.put("PageNum", pagedata.getPageNum());
        data.put("PageSize", pagedata.getPageSize());
        return ResultDTO.successOf(data,GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价计划-分解保存
     * @param id 计划任务分解表单中的ID
     * @param discerner 辨识人
     * @param evaluator 评价人
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/decomposeRiskIdenEva")
    public ResultDTO decomposeRiskIdenEva
        (@RequestParam("id") String id,
         @RequestParam("discerner") String discerner,
         @RequestParam("evaluator") String evaluator) {
        Long companyId=this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        tRiskTaskAllocationService.insertDiscernerAndEvaluator
                (companyId,id,discerner,evaluator,userId);
        //风险点分解保存后TaskAll中State修改为分解中(3)
        tRiskTaskAllocationService.updateByIdStateThree(companyId,id,userId);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价计划-派发按钮
     * @param id 风险辨识评价计划ID
     * @param state 状态( 分解中 2 ~ 辨识中 3 )
     * @param personidenevaId 分解人ID             
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/distributionRIEBut")
    public ResultDTO distributionRIEBut 
        (@RequestParam("id") String id,@RequestParam("state") String state) {
        Long companyId = this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        
        //查出来所有属于该分解人下未分解的计划
        List<TRiskTaskAllocationList> taskAllList = tRiskTaskAllocationService
            .getByPersonidenevaId(companyId,String.valueOf(userId));
        List<String> idList = new ArrayList<>();
        for (int i = 0; i < taskAllList.size(); i++) {
            idList.add(String.valueOf(taskAllList.get(i).getId()));
        }
        if (taskAllList.size() != 0 && idList.size() != 0) {
            tRiskTaskAllocationService.updateResolveById(id,idList);
            String  states = "2";//分解中的状态
            List<TRiskTaskAllocationList> taskAll =
                tRiskTaskAllocationService.selectById(companyId, id,states);
           if(taskAll.size() == 0){
                tRiskIdentEvalStatusService.decomposeRiskIdenEva(companyId,id,state,userId);
            }else if(taskAll.size() != 0) {
               return ResultDTO.errorOf (UserResponseEnums.T_R_TASK_ALL_RELEASE_PARAMETERS_ERROR); 
            }
        } 
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识-风险辨识-添加设备设施检查项
     * @param taskAllocatId 风险评价计划任务分配ID
     * @param riskpointType 风险计划类型 ss00 : 设备设施 ; zy00 : 作业活动 ; gy00 : 工艺节点     
     *  checkItems 设备设施检查项类
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/addTRiskCheckItems")
    public ResultDTO addTRiskCheckItems(@RequestParam("taskAllocatId") Integer taskAllocatId,
         @RequestParam("riskpointType") String riskpointType,
         TRiskProcessInspectionItemList proInItems) {
        Long companyId = this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        TRiskTaskAllocationList tAll=tRiskTaskAllocationService.
            getByAllAndId(companyId, taskAllocatId.toString());
        int triskidentevalsId = tAll.getTriskidentevalsId();
         int res = 0;
            if(riskpointType.equals("ss00")) {// 设备设施
                TRiskCheckItemsList checkItems = new TRiskCheckItemsList();
                checkItems.setCompanyId(this.getSessionUserCompanyId());
                checkItems.setTriskidentevalsId(triskidentevalsId);
                checkItems.setTaskAllocatId(taskAllocatId);
                checkItems.setInspectionItems(proInItems.getInspectionItems());
                checkItems.setInspectionStandard(proInItems.getInspectionStandard());
                checkItems.setNonCompliance(proInItems.getNonCompliance());
                checkItems.setMainConsequences(proInItems.getMainConsequences());
                res =tRiskCheckItemsService.insertTRiskCheckItems(checkItems);
            } else if(riskpointType.equals("zy00")) {// 作业活动
                TRiskJobCheckItemList jobCheckItems = new TRiskJobCheckItemList();
                jobCheckItems.setCompanyId(this.getSessionUserCompanyId());
                jobCheckItems.setTriskidentevalsId(triskidentevalsId);
                jobCheckItems.setTaskAllocatId(taskAllocatId);
                jobCheckItems.setInspectionItems(proInItems.getInspectionItems());
                jobCheckItems.setInspectionStandard(proInItems.getInspectionStandard());
                jobCheckItems.setNonCompliance(proInItems.getNonCompliance());
                res = tRiskJobCheckItemService.insertJobCheckItems(jobCheckItems);
            } else if(riskpointType.equals("gy00")) {// 工艺节点
                TRiskProcessInspectionItemList proInItem = new TRiskProcessInspectionItemList();
                proInItem.setCompanyId(this.getSessionUserCompanyId());
                proInItem.setTriskidentevalsId(triskidentevalsId);
                proInItem.setTaskAllocatId(taskAllocatId);
                proInItem.setInspectionItems(proInItems.getInspectionItems());
                proInItem.setInspectionStandard(proInItems.getInspectionStandard());
                proInItem.setNonCompliance(proInItems.getNonCompliance());
                proInItem.setMainConsequences(proInItems.getMainConsequences());
                proInItem.setDeviation(proInItems.getDeviation());
                proInItem.setPossiblereasons(proInItems.getPossiblereasons());
                proInItem.setMajorconsequences(proInItems.getMajorconsequences());
                res = tRiskProcessInspectionItemService.insertProcessInspectionItem(proInItem);
            }
            
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识-风险辨识-编辑设备设施检查项
     * @param id 检查项ID
     * @param riskpointType 风险计划类型 ss00 : 设备设施 ; zy00 : 作业活动 ; gy00 : 工艺节点 
     *  checkItems 检查项类
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/updateTRiskCheckItems")
    public ResultDTO updateCheckItems
    (@RequestParam(value = "id",required = false,defaultValue = "0") String id,
     @RequestParam("riskpointType") String riskpointType,
     TRiskProcessInspectionItemList proInItems) {
        int res = 0;
        if(riskpointType.equals("ss00")){// 设备设施
            TRiskCheckItemsList checkItems = new TRiskCheckItemsList();
            checkItems.setInspectionItems(proInItems.getInspectionItems());
            checkItems.setInspectionStandard(proInItems.getInspectionStandard());
            checkItems.setNonCompliance(proInItems.getNonCompliance());
            checkItems.setMainConsequences(proInItems.getMainConsequences());
            res =tRiskCheckItemsService.updateTRiskCheckItems(id,checkItems);
        }else if(riskpointType.equals("zy00")){// 作业活动
            TRiskJobCheckItemList jobCheckItems = new TRiskJobCheckItemList();
            jobCheckItems.setInspectionItems(proInItems.getInspectionItems());
            jobCheckItems.setInspectionStandard(proInItems.getInspectionStandard());
            jobCheckItems.setNonCompliance(proInItems.getNonCompliance());
            res = tRiskJobCheckItemService.updateJobCheckItems(id,jobCheckItems);
        }else if(riskpointType.equals("gy00")){// 工艺节点
            TRiskProcessInspectionItemList proInItem = new TRiskProcessInspectionItemList();
            proInItem.setInspectionItems(proInItems.getInspectionItems());
            proInItem.setInspectionStandard(proInItems.getInspectionStandard());
            proInItem.setNonCompliance(proInItems.getNonCompliance());
            proInItem.setMainConsequences(proInItems.getMainConsequences());
            proInItem.setDeviation(proInItems.getDeviation());
            proInItem.setPossiblereasons(proInItems.getPossiblereasons());
            proInItem.setMajorconsequences(proInItems.getMajorconsequences());
            res = tRiskProcessInspectionItemService.updateProcessInspectionItem(id,proInItem);
        }
        if(res < 0){
            return ResultDTO.errorOf(UserResponseEnums.CHECK_ITEM_ADD_FAILED_ERRORUSER);
        }
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识-风险辨识-删除检查项
     * @param id 检查项ID
     * @param riskpointType 风险点清单类型
     *        ss00 : 设备设施清单 ;
     *        zy00 : 作业活动清单 ;
     *        gy00 : 工艺节点清单 ;
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/deleteTRiskCheckItems")
    public ResultDTO deleteTRiskCheckItems(@RequestParam("id") String id,
        @RequestParam("riskpointType") String riskpointType){
        if (riskpointType.equals("ss00")){
            tRiskCheckItemsService.deleteTRiskCheckItems(id);
        }else if (riskpointType.equals("zy00")){
            tRiskJobCheckItemService.deleteJobCheckItems(id);
        }else if (riskpointType.equals("gy00")){
            tRiskProcessInspectionItemService.deleteProcessInspectionItem(id);
        }
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价计划-风险辨识提交按钮
     * @param id 风险辨识评价计划ID
     * @param state 状态 评价中(4)
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/submissionRIEBut")
    public ResultDTO submissionRIEBut(@RequestParam("id") String id,
          @RequestParam("state") String state) {
        Long companyId=this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        //查出来所有属于该辨识人下未辨识的计划
        List<TRiskTaskAllocationList> taskAllList = tRiskTaskAllocationService
            .getByDiscernerId(companyId,String.valueOf(userId));
        List<String> idList = new ArrayList<>();
        for (int i = 0; i < taskAllList.size(); i++) {
            idList.add(String.valueOf(taskAllList.get(i).getId()));
        }
        if(taskAllList.size() != 0 && idList.size() != 0) {
            //风险辨识后TaskAll中State修改为已辨识/评价中(4)
            tRiskTaskAllocationService.updateByRecognizeId(id,idList);
            String  states = "3";//辨识中(3)的状态
            List<TRiskTaskAllocationList> taskAll =
                tRiskTaskAllocationService.selectById(companyId, id,states);
            if(taskAll.size() == 0){
                tRiskIdentEvalStatusService.identificationRiskIdenEva
                    (companyId,id,state,userId);
            }else{
                return ResultDTO.errorOf(UserResponseEnums.T_R_TASK_ALL_IDENTIFY_PARAMETERS_ERROR);
            }
        }else{
            return ResultDTO.errorOf(UserResponseEnums.CHECK_ITEM_ADD_FAILED_ERRORUSER);
        }
        
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价计划-风险评价按钮-检查项-评价按钮
     * @param taskAllocatId 风险辨识评价计划ID
     * @param checkitemsId 检查项ID
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/evaluateRIEButsAndCheck")
    public ResultDTO evaluateRIEButsAndCheck
        (@RequestParam("taskAllocatId") String taskAllocatId,
         @RequestParam("checkitemsId") String checkitemsId) {
        Long companyId=this.getSessionUserCompanyId();
        List<TRiskAssessmentMeasuresList>
                asseMeasList=tRiskAssessmentMeasuresService
                .getByRisIdAndRiskpointsIdAndCheckitemsId(companyId,taskAllocatId,checkitemsId);
        List<TRiskValueLevelList> valueLevList = new ArrayList<>();
        for (TRiskAssessmentMeasuresList assMe : asseMeasList) {
            valueLevList =tRiskValueLevelService.getValueLevelList
                    (companyId,assMe.getId().intValue());
        }
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("asseMeasList", asseMeasList);//风险评价措施表
        data.put("valueLevList", valueLevList);//风险评价-措施-风险值等
        return ResultDTO.successOf(data,GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险评价-检查项-评价-添加风险评价措施
     * @param taskAllocatId 风险评价计划任务分配ID
     * @param checkitemsId 检查项ID
     * @param riskAssess 风险评价措施类
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/addTRiskAsseMeas")
    public ResultDTO addTRiskAsseMeas
           (
           @RequestParam("taskAllocatId") Integer taskAllocatId,
           @RequestParam("checkitemsId") Integer checkitemsId,
           TRiskAssessmentMeasuresList riskAssess){
        Long companyId = this.getSessionUserCompanyId();
        riskAssess.setCompanyId(companyId);
        riskAssess.setTaskAllocatId(taskAllocatId);
        riskAssess.setCheckitemsId(checkitemsId);
        tRiskAssessmentMeasuresService.insertTRiskAsseMeas(riskAssess);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险评价-检查项-评价-修改风险评价措施
     * @param riskAssess 风险评价措施类
     * @param id  风险评价措施id
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/updateTRiskAsseMeas")
    public ResultDTO updateTRiskAsseMeas
        (@RequestParam(value ="id",required = false,defaultValue = "0")
             String id,TRiskAssessmentMeasuresList riskAssess){
        tRiskAssessmentMeasuresService.updateTRiskAsseMeas(id,riskAssess);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价计划-风险评价-退回按钮
     * @param id 风险辨识评价计划ID
     * @param state 状态评价中(8)改为待辨识(6)
     * @return 返回ResultDTO对象
     * @todo 保留未必使用
     */
    @RequestMapping("/sendBackRIEBut")
    public ResultDTO sendBackRIEBut(@RequestParam("id") String id,
         @RequestParam("state") String state) {
        Long companyId = this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        tRiskIdentEvalStatusService.evaluationDecomposeRiskIdenEva
                (companyId,id,state,userId);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价计划-风险评价-风险点评价退回
     * @param id 风险辨识评价计划-分析评价任务分配ID
     * @param state 状态评价中(4)改为辨识中(3)
     * @param returnReason 风险点评价退回原因
     * @return 返回ResultDTO对象
     */
    @RequestMapping("/sendBackTaskAllReturnReason")
    public ResultDTO sendBackTaskAllReturnReason(@RequestParam("id") String id,
           @RequestParam("state") String state,String returnReason) {
        Long companyId = this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        tRiskTaskAllocationService.sendBackTaskAllReturnReason(companyId,id,state,returnReason,userId);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价计划-评价提交
     * @param id 风险辨识评价计划ID
     * @param state 状态审核中(5)
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/evaluateRiskIdenEva")
    public ResultDTO evaluateRiskIdenEva(@RequestParam("id") String id,
         @RequestParam("state") String state){
        Long companyId=this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        //查出来所有属于该辨识人下未辨识的计划
        List<TRiskTaskAllocationList> taskAllList = tRiskTaskAllocationService
            .getByEvaluatorId(companyId,String.valueOf(userId));
        List<String> idList = new ArrayList<>();
        for (int i = 0; i < taskAllList.size(); i++) {
            idList.add(String.valueOf(taskAllList.get(i).getId()));
        }
        if( taskAllList.size() > 0 && idList.size() > 0 ) {
            //风险评价措施添加之后该条风险点状态要修改为 5 : 审核中/(已评价) 
            tRiskTaskAllocationService.updateByAppraiseId(id,idList);
            String  states = "4"; // 4 : 评价中
            List<TRiskTaskAllocationList> taskAll =
                tRiskTaskAllocationService.selectById(companyId, id,states);
            if(taskAll.size() == 0) {
                tRiskIdentEvalStatusService.evaluateRiskIdenEva(companyId,id,state,userId);
            } else {
                return ResultDTO.errorOf(UserResponseEnums.T_R_TASK_ALL_APPRAISE_PARAMETERS_ERROR);
            }
        }else{
            return ResultDTO.errorOf(UserResponseEnums.ASSE_MEAS_ADD_FAILED_ERRORUSER);
        }
        
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价计划-评价审核-审核-审核
     * @param id 风险辨识评价计划ID
     * @param riskpointsId 风险点ID
     * @param taskAllocatId 风险评价计划任务分配ID
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/evaluationRiskIdenEvaAudit")
    public ResultDTO evaluationRiskIdenEvaAudit(
         @RequestParam("id") String id,
         @RequestParam("taskAllocatId") String taskAllocatId,
         @RequestParam("riskpointsId") String riskpointsId){
        Long companyId=this.getSessionUserCompanyId();
        String type = "4";
        //评价任务分配-风险辨识
        List<TRiskTaskAllocationList> taskAllocation=tRiskTaskAllocationService.
            getByIds(companyId,taskAllocatId,type);
        //风险点
        List<TEquipFacStatusList> tEquipFacStatus = tEquipFacStatusService
                .getById(companyId,riskpointsId);
        //检查项
        List<TRiskCheckItemsList> tRiskCheckItems =tRiskCheckItemsService.
                getById(companyId,taskAllocatId);
        //对象评价审核
        List<TRiskObjectEvaluationAuditList> tRObjectEvaAudit =
          tRiskObjectEvaluationAuditService.selectByRObjEvaAudit(companyId, taskAllocatId);
        //审核记录
        List<TRiskAuditRecordsList> tRiskAuditRecords= tRiskAuditRecordsService
             .getByRIESIdAndRPointId(companyId,taskAllocatId);
        List<String> proposalList = new ArrayList<>();
        //建议
        for (TRiskTaskAllocationList all : taskAllocation){
            proposalList.add(all.getProposal());
        }

        Map<String, Object> data = new HashMap<String, Object>();
        data.put("taskAllocation", taskAllocation);//评价任务分配-风险辨识
        data.put("tEquipFacStatus", tEquipFacStatus);//风险点
        data.put("tRiskCheckItems", tRiskCheckItems);//检查项
        data.put("tRObjectEvaAudit", tRObjectEvaAudit);//对象评价审核
        data.put("tRiskAuditRecords", tRiskAuditRecords);//审核记录
        data.put("proposal", proposalList);//建议

        return ResultDTO.successOf(data,GeneralResponseEnums.SUCCESS);

    }

    /**
     * 风险辨识评价计划-评价审核-审核-审核-对象评价审核的确定
     * @param id 风险辨识评价计划ID
     * @param taskAllocatId 分析评价任务分配表中的ID
     * @param proposal 建议
     * @param auditproject 审核项目
     * @param compliance 是否符合 0 : 不符合 ; 1 : 符合
     * @param inconformity 不符合原因
     * @return 返回 ResultDTO对象
     */
    @RequestMapping("/reviewConfirmRiskIdenEvaAudit")
    public ResultDTO reviewConfirmRiskIdenEvaAudit
        (@RequestParam("id") String id,
         @RequestParam("taskAllocatId") String taskAllocatId,
         @RequestParam(value = "proposal",required = false,defaultValue = "0") String proposal,
         @RequestParam(value="auditproject") String auditproject,
         @RequestParam(value="compliance") String compliance,
         @RequestParam(value="inconformity",required = false,defaultValue = "0") String inconformity) {
        Long companyId= this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        List<TRiskObjectEvaluationAuditList> rObjEvaList = tRiskObjectEvaluationAuditService
            .selectByRObjEvaAudit(companyId,taskAllocatId);
        if (rObjEvaList.size()!=0) {
            tRiskObjectEvaluationAuditService.deleteObjEvaAudit(companyId,taskAllocatId);
        }
        int objRes= tRiskObjectEvaluationAuditService.insertTRObjectEvaluationAudit
                 (companyId,id,taskAllocatId,auditproject,compliance,inconformity);
        int proRes=tRiskTaskAllocationService.updateByIdAndProposal(taskAllocatId,proposal);
        if (objRes!=0 && proRes != 0) {
            //评价审核-审核-审核-对象评价审核该条风险点状态要修改为已审核(10)
            tRiskTaskAllocationService.updateByIdStateEleven
                (companyId,Integer.valueOf(id),taskAllocatId,userId);
        } else if (objRes==0 || proRes == 0) {
            return ResultDTO.errorOf(UserResponseEnums.T_OBJ_EVA_AUDIT_FAILURE_ERROR);
        }

        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价计划-评价审核-退回按钮
     * @param id 风险辨识评价计划ID
     * @param state 状态审核中(5)改为辨识中(3)
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/returnedBackRIEBut")
    public ResultDTO returnedBackRIEBut(@RequestParam("id") String id,
         @RequestParam("state") String state) {
        Long companyId=this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        tRiskIdentEvalStatusService.auditDecomposeRiskIdenEva(companyId,id,state,userId);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价计划-评价审核-提交结果返回
     * @param id 风险辨识评价计划ID
     * @param auditfind 审核结果
     * @param auditopinion 审核意见
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/verifyAssessmentAuditRIEABut")
    public ResultDTO verifyAssessmentAuditRIEABut
        (@RequestParam("id") String id,
         @RequestParam("auditfind") String auditfind,
         @RequestParam(value = "auditopinion",
         required = false,defaultValue = "1") String auditopinion) {
        
        Long companyId=this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        
        SysUser user = userService.getById(userId);
        
        Organization isafeorg = organizationService.getByIsafeorg(companyId);
        String isafeorgLeadUserId =String.valueOf(isafeorg.getLeadUserid()); 
        
        Organization topPid = organizationService.getByTopPid(companyId);
        String topPidLeadUserId =String.valueOf(topPid.getLeadUserid());
        
        //第一审核人
        List<TRiskProcessOperationRecordList> departAudOperaList = tRiskProcessOperationRecordService
            .getByOperatorAndDepart(companyId,userId.toString());
        
        List<String> idLists = new ArrayList<>();
        if(departAudOperaList.size()>0) {
            for (int i = 0; i <departAudOperaList.size() ; i++) {
                idLists.add(String.valueOf(departAudOperaList.get(i).getTaskAllocatId()));
            }
        }

        //安全部门审核
        List<TRiskProcessOperationRecordList> securAudOperaList = tRiskProcessOperationRecordService
            .getByOperatorAndSecur(companyId,userId.toString());

        //最终审核人
        List<TRiskProcessOperationRecordList> endAudOperaList = tRiskProcessOperationRecordService
            .getByOperatorAndEnd(companyId,userId.toString());

        List<TRiskTaskAllocationList> taskAllocat =
            tRiskTaskAllocationService.getById(companyId,id);
        
        //风险评价审核-审核-对象评价审核
        List<TRiskObjectEvaluationAuditList> tRiObjEvaAudList =
            tRiskObjectEvaluationAuditService.selectByRObjEvaAuditZero(companyId, id);

        /**
         * 部门负责人审核 ,审核后将status修改为 1 
         */
        if (departAudOperaList.size()>0) {
                if ("1".equals(auditfind)) {//审核通过
                    if (tRiObjEvaAudList.size()==0) {//只有当对象审核中全部为是才可以通过
                        String states ="5";//部门内部的负责人审核通过状态为审核中(5) 
                        tRiskTaskAllocationService.updateByDepaAuditId(id,idLists);
                        String  statesss = "5"; // 5 : 审核中
                        List<TRiskTaskAllocationList> taskAll =
                            tRiskTaskAllocationService.selectById(companyId, id,statesss);
                        if(taskAll.size()==0){
                            tRiskIdentEvalStatusService.depaPassReview(companyId,id,states,auditfind,userId);
                        }else if(taskAll.size() > 0){
                            return ResultDTO.errorOf(UserResponseEnums
                                .T_R_TASK_ALL_NOT_AUDIT_PARAMETERS_ERROR);
                        }

                        Information info = new Information();
                        info.setTitle("风险辨识评价计划");
                        info.setDepartment(String.valueOf(companyId));
                        info.setStatus("0");
                        info.setDetails
                            ("风险辨识评价计划部门内部的负责人通过,请安全部门审核人及时处理!!");
                        info.setSendId(userId);//发送者
                        info.setTargetId(isafeorg.getLeadUserid().longValue());//接收者
                        info.setCreateTime(new Date());
                        info.setUpdateTime(new Date());
                        informationService.insertInfo(info);
                    } else if(tRiObjEvaAudList.size()!=0) {//对象审核中存在否弹出提示,保持状态
                        return ResultDTO.errorOf(UserResponseEnums
                            .TASK_NOT_ALLOWED_TO_PASS);
                    }
                    //部门内部的负责人审核未通过状态为 6
                } else if ("0".equals(auditfind) && StringUtils.isNotBlank(auditopinion)) {
                    if (tRiObjEvaAudList.size()!=0) {//只有当对象审核中全部为是才可以通过
                        String states = "6";//被退回(审核)后状态直接修改成辨识中
                        tRiskIdentEvalStatusService.depaNoPassReview
                            (companyId, id, states,auditfind,userId);

                        Information info = new Information();
                        info.setTitle("风险辨识评价计划");
                        info.setDepartment(String.valueOf(companyId));
                        info.setStatus("0");
                        info.setDetails("风险辨识评价计划审核未通过,请辨识人及时处理!!");
                        info.setSendId(userId);//发送者
                        info.setTargetId(1L);//接收者
                        info.setCreateTime(new Date());
                        info.setUpdateTime(new Date());
                        informationService.insertInfo(info);
                    } else if(tRiObjEvaAudList.size()==0) {//对象审核中存在否弹出提示,保持状态
                        return ResultDTO.errorOf(UserResponseEnums
                            .TASK_OVERRULED_NOT_ALLOWED);
                    }
                }
        } else if(isafeorgLeadUserId.equals(String.valueOf(userId)) && securAudOperaList.size()>0)
        /**
         * 安全管理部门负责人 , 审核后将status修改为 2
         */
        { //安全部门审核通过状态为5
            if ("1".equals(auditfind)) {//审核通过
                if(tRiObjEvaAudList.size()==0) {//只有当对象审核中全部为是才可以通过
                    String states = "5";//安全部门审核审核通过状态为审核中(5)
                    tRiskIdentEvalStatusService.securityPassReview
                        (companyId, id, states,auditfind,userId);

                    Information info = new Information();
                    info.setTitle("风险辨识评价计划");
                    info.setDepartment(String.valueOf(companyId));
                    info.setStatus("0");
                    info.setDetails("风险辨识评价计划审核已通过,请最终审核人及时处理!!");
                    info.setSendId(userId);//发送者
                    info.setTargetId(topPid.getLeadUserid().longValue());//接收者
                    info.setCreateTime(new Date());
                    info.setUpdateTime(new Date());
                    informationService.insertInfo(info);
                } else if(tRiObjEvaAudList.size()!=0) {//对象审核中存在否弹出提示,保持状态
                    return ResultDTO.errorOf(UserResponseEnums
                        .TASK_NOT_ALLOWED_TO_PASS);
                } //安全部门审核未通过状态为9
            } else if ("0".equals(auditfind) && StringUtils.isNotBlank(auditopinion)) {
                if (tRiObjEvaAudList.size()!=0) {//只有当对象审核中全部为是才可以通过
                    String states = "9";//9 : 被退回(审核)
                    tRiskIdentEvalStatusService.securityNoPassReview
                        (companyId, id, states,auditfind,userId);

                    Information info = new Information();
                    info.setTitle("风险辨识评价计划");
                    info.setDepartment(String.valueOf(companyId));
                    info.setStatus("0");
                    info.setDetails("风险辨识评价计划审核未通过,请部门审核人及时处理!!");
                    info.setSendId(userId);//发送者
                    info.setTargetId(1L);//接收者
                    info.setCreateTime(new Date());
                    info.setUpdateTime(new Date());
                    informationService.insertInfo(info);
                } else if (tRiObjEvaAudList.size()==0) {//对象审核中存在否弹出提示,保持状态
                    return ResultDTO.errorOf(UserResponseEnums
                        .TASK_OVERRULED_NOT_ALLOWED);
                }
            }
            /**
             * 最终审核人 ,审核后将status修改为 3
             */
        } else if (topPidLeadUserId.equals(String.valueOf(userId)) && endAudOperaList.size()>0) {
            //公司最高级负责人审核通过后修改状态已完成
            if (auditfind.equals("1")) {//最终审核人审核通过状态为11或者0
                if (tRiObjEvaAudList.size()==0) {//只有当对象审核中全部为是才可以通过
                    String states = "0";//最终审核人审核通过状态为已完成(0)
                    tRiskIdentEvalStatusService.finalPassReview
                        (companyId, id, states,auditfind,userId);

                    Information info = new Information();
                    info.setTitle("风险辨识评价计划");
                    info.setDepartment(String.valueOf(companyId));
                    info.setStatus("0");
                    info.setDetails("风险辨识评价计划审核通过!!");
                    info.setSendId(userId);//发送者
                    info.setTargetId(topPid.getLeadUserid().longValue());//接收者
                    info.setCreateTime(new Date());
                    info.setUpdateTime(new Date());
                    informationService.insertInfo(info);
                } else if (tRiObjEvaAudList.size()!=0) {//对象审核中存在否弹出提示,保持状态
                    return ResultDTO.errorOf(UserResponseEnums
                        .TASK_NOT_ALLOWED_TO_PASS);
                }
                //最终审核人审核退回状态为 9
            } else if ("0".equals(auditfind) && StringUtils.isNotBlank(auditopinion)) {
                if(tRiObjEvaAudList.size()!=0) {//只有当对象审核中全部为是才可以通过
                    String states = "9";//被退回(审核)
                    tRiskIdentEvalStatusService.finalNoPassReview
                        (companyId, id, states,auditfind,userId);

                    Information info = new Information();
                    info.setTitle("风险辨识评价计划");
                    info.setDepartment(String.valueOf(companyId));
                    info.setStatus("0");
                    info.setDetails("风险辨识评价计划审核未通过,请安全部门审核人及时处理!!");
                    info.setSendId(userId);//发送者
                    info.setTargetId(1L);//接收者
                    info.setCreateTime(new Date());
                    info.setUpdateTime(new Date());
                    informationService.insertInfo(info);
                } else if (tRiObjEvaAudList.size()==0) { //对象审核中存在否弹出提示,保持状态
                    return ResultDTO.errorOf(UserResponseEnums.TASK_OVERRULED_NOT_ALLOWED);
                }
            }
        } else {
           return ResultDTO.errorOf(UserResponseEnums.USER_NOT_THE_REVIEWER);
        }
            
        List<TRiskAuditRecordsList> auditRecoList = new ArrayList<>();
        for (int i = 0; i < taskAllocat.size(); i++) {
            //风险评价审核-审核记录
            TRiskAuditRecordsList tRiskAuditRecords = new TRiskAuditRecordsList();
            tRiskAuditRecords.setCompanyId(companyId);
            tRiskAuditRecords.setTriskidentevalsId(Integer.valueOf(id));
            tRiskAuditRecords.setTaskAllocatId(taskAllocat.get(i).getId().intValue());
            if(isafeorgLeadUserId.equals(String.valueOf(userId)) && securAudOperaList.size()>0){
                tRiskAuditRecords.setAuditlink(isafeorg.getName());
            }else if(topPidLeadUserId.equals(String.valueOf(userId)) && endAudOperaList.size()>0){
                tRiskAuditRecords.setAuditlink(topPid.getName());
            }
            if(auditfind.equals("1")){
                tRiskAuditRecords.setAuditfind("审核通过");
            }else if(auditfind.equals("0")){
                tRiskAuditRecords.setAuditfind("审核不通过");
            }
            tRiskAuditRecords.setAuditopinion(auditopinion);
            tRiskAuditRecords.setReviewer(user.getName());
            tRiskAuditRecords.setAudittime(new Date());
            tRiskAuditRecords.setPersoncontrol(user.getName());
            auditRecoList.add(tRiskAuditRecords);
        }
        tRiskAuditRecordsService.insertTRiskAuditRecords(auditRecoList);

        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 风险辨识评价计划列表导出
     * @param response
     * @param id 风险辨识评价计划ID
     * @throws IOException
     */
    @GetMapping("/exportRiskIdentEvalStatusList")
    public void exportRiskIdentEvalStatusList (HttpServletResponse response,
          @RequestParam(value = "id",required = false
              ,defaultValue = "0") String id) throws IOException {
        Long companyId=this.getSessionUserCompanyId();
        Page<TRiskIdentEvalStatusList> pagedata = tRiskIdentEvalStatusService
                .getExportRiskIdentEvalStatusList(companyId,id);
        List<TRiskIdentEvalStatusList> list = pagedata.getResult();
        ExcelUtil2<TRiskIdentEvalStatusList> util = new
                ExcelUtil2<TRiskIdentEvalStatusList>(TRiskIdentEvalStatusList.class);
        util.exportExcel(response, list, "风险辨识评价计划列表");
    }

}
